//
//  BackGroundView.m
//  1243
//
//  Created by apple on 16/6/30.
//  Copyright © 2016年 1243. All rights reserved.
//

#import "BackGroundView.h"

@interface BackGroundView ()<UIScrollViewDelegate>

@end

@implementation BackGroundView
{
}
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backGroungView = [[UIScrollView alloc]initWithFrame:frame];
        self.backGroungView.delegate = self;
        [self.backGroungView setContentSize:CGSizeMake(WIDTH * 3, HEIGHT -64)];
        self.backGroungView.showsHorizontalScrollIndicator = NO;
        self.backGroungView.pagingEnabled = YES;
        
        [self addSubview:self.backGroungView];
    }
    return self;
}

- (void)jumpToIndex:(NSInteger )index {
    [self.backGroungView setContentOffset:CGPointMake(WIDTH *index, 0)];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    NSLog(@"%f",self.backGroungView.contentOffset.x);
        if (self.backGroungView.contentOffset.x < [UIScreen mainScreen].bounds.size.width) {
            self.changeScrollBlock(0);
        }else if (self.backGroungView.contentOffset.x == [UIScreen mainScreen].bounds.size.width) {
            self.changeScrollBlock(1);
        }else if (self.backGroungView.contentOffset.x >= [UIScreen mainScreen].bounds.size.width *2){
            self.changeScrollBlock(2);
        }
}


@end
